package com.presto.directo.utils

import android.app.Activity
import android.content.Context
import android.view.inputmethod.InputMethodManager
import android.widget.TextView

private val activities = arrayListOf<Activity>()

fun Activity.add() {
    activities.add(this)
}

fun Activity.remove() {
    activities.remove(this)
}

fun exit() {
    activities.forEach {
        if (!it.isFinishing) {
            it.finish()
        }
    }
}

fun Activity.showInfo(textView: TextView, res: Int, index: Int, minus: Boolean = true, minusNum: Int = 1) {
    if (minus) {
        if (index - minusNum >= 0) {
            textView.text = resources.getStringArray(res)[index - minusNum]
        }
    } else {
        textView.text = resources.getStringArray(res)[index]
    }
}

fun Activity.hideKeyBoard() {
    val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.hideSoftInputFromWindow(window.decorView.windowToken, 0)
}